<?php
/**
 * PhpStorm
 * User: zucheng
 * Date: 2019/4/12
 */

use Illuminate\Database\Seeder;

class RouteTableSeeder extends Seeder
{
    /**
     * Run the database seeds.
     * @return void
     */
    public function run()
    {
        \App\Models\DriverRoutes::truncate();
        \App\Models\OwnerRoutes::truncate();
        $ownerMem  = \App\Models\Member::where('role_id', 20)->first();
        $driverMem = \App\Models\Member::where('role_id', 10)->first();

        // 基础数据
        $data                      = [];
        $data['src_province_code'] = 110000;
        $data['src_city_code']     = 110100;
        $data['src_district_code'] = 110105;
        $data['src_address']       = '广顺南大街';
        $data['dst_province_code'] = 410000;
        $data['dst_city_code']     = 410900;
        $data['dst_district_code'] = 410927;
        $data['dst_address']       = '孙口镇凤台大道002号';

        // 生成货主路由
        $ownerRoutesData               = $data;
        $ownerRoutesData['owner_uuid'] = $ownerMem['uuid'];
        $ownerRoutesData['src_location'] = Amap::geo($data['src_address'], $data['src_city_code'])->location;
        $ownerRoutesData['dst_location'] = Amap::geo($data['dst_address'], $data['dst_city_code'])->location;
        if (!empty($ownerRoutesData['src_location']) && !empty($ownerRoutesData['dst_location'])) {
            // 驾驶距离
            $ownerRoutesData['driving_distance'] = Amap::distance($ownerRoutesData['src_location'], $ownerRoutesData['dst_location'], 1)[0]->distance;

            // 直线距离
            $ownerRoutesData['line_distance'] = Amap::distance($ownerRoutesData['src_location'], $ownerRoutesData['dst_location'], 0)[0]->distance;
        }
        \App\Models\OwnerRoutes::create($ownerRoutesData);


        // 生成订阅路由
        $driverRoutesData                = $data;
        $driverRoutesData['driver_uuid'] = $driverMem['uuid'];
        \App\Models\DriverRoutes::create($driverRoutesData);

    }
}